export function gpsToBaidu(lng, lat) {
    return new Promise((resolve, reject) => {
        // 确保坐标是数字类型
        const lngNum = typeof lng === 'string' ? parseFloat(lng) : lng;
        const latNum = typeof lat === 'string' ? parseFloat(lat) : lat;

        if (isNaN(lngNum) || isNaN(latNum)) {
            reject(new Error('无效的坐标值'));
            return;
        }

        if (!window.BMapGL || !BMapGL.Convertor) {
            reject(new Error('百度地图API未加载'));
            return;
        }

        const convertor = new BMapGL.Convertor();
        const pointArr = [new BMapGL.Point(lngNum, latNum)];

        convertor.translate(pointArr, 1, 5, (data) => {
            if (data.status === 0) {
                resolve(data.points[0]);
            } else {
                reject(new Error('坐标转换失败，状态码: ' + data.status));
            }
        });
    });
}